<#include "include/_meta.html"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加管理员</title>
</head>
<body>
	<div class="page-container" id="listResult">
		<form onsubmit="return false" class="form form-horizontal" id="form-article-add">
			<div class="row cl">
				<label for="username" class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>账户名称：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="请输入账户名" id="username"
					       name="username">
				</div>
			</div>
			<div class="row cl">
				<label for="userpwd" class="form-label col-xs-4 col-sm-2"><span
							class="c-red">*</span>密码：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="password" class="input-text" value="" placeholder="请输入密码" id="userpwd"
					       name="userpwd">
				</div>
			</div>
			<div class="row cl">
				<label for="password_again" class="form-label col-xs-4 col-sm-2">
					<span class="c-red">*</span>确认密码：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="password" name="password_again" id="password_again" placeholder="请再输一次密码"
					       value="" class="input-text">
				</div>
			</div>
			<div class="row cl">
				<label for="nickname" class="form-label col-xs-4 col-sm-2">账户昵称：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" name="nickname" id="nickname" placeholder="请输入昵称" value=""
					       class="input-text">
				</div>
			</div>
			<div class="row cl">
				<label for="realname" class="form-label col-xs-4 col-sm-2">
					<span class="c-red">*</span>真实姓名：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" name="realname" id="realname" placeholder="请输入真实姓名" value=""
					       class="input-text">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-2">
					<span class="c-red">*</span>手机号码：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" name="mobile" id="mobile" placeholder="请输入手机号码" value=""
					       class="input-text">
				</div>
			</div>
			<div class="row cl">
				<label for="email" class="form-label col-xs-4 col-sm-2">账户邮箱：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" name="email" id="email" placeholder="请输入账户邮箱" value=""
					       class="input-text">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>员工工号：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" name="personid" id="personid" placeholder="请输入员工工号" value=""
					       class="input-text">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-2">用户状态：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="radio" name="userstate" checked value="1">&nbsp;正常&nbsp;&nbsp;&nbsp;
					<input type="radio" name="userstate" value="0">&nbsp;锁定
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>所属部门：</label>
				<div class="formControls col-xs-8 col-sm-9">
          <span class="select-box">
            <select class="select" name="deptcode">
              <option value="-1">请选择</option>
              <option :value="dept.deptid" v-for="dept in depts">{{dept.deptname}}</option>
            </select>
          </span>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>角色：</label>
				<div class="formControls col-xs-8 col-sm-9">
          <span class="select-box">
				<select class="select" name="rolecode">
					<option value="-1">请选择</option>
					<option :value="role.roleid" v-for="role in roles">{{role.rolename}}</option>
				</select>
				</span>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">备注：</label>
				<div class="formControls col-xs-8 col-sm-9">
          <textarea id="remark" name="" cols="" rows="" class="textarea"
                    placeholder="说点什么...100个字符以内" dragonfly="true"
                    onKeyUp="textarealength(this,100)"></textarea>
					<p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
				</div>
			</div>
			<div>
				<input type="submit" class="btn btn-success" value="提交">
				<input type="button" id="cancelBtn" class="btn btn-default" value="取消">
			</div>
		</form>
	</div>
    <#include "include/_footer.html"/>
	<script type="text/javascript" src="/lib/webuploader/0.1.5/webuploader.min.js"></script>
	<script type="text/javascript" src="/lib/ueditor/1.4.3/ueditor.config.js"></script>
	<script type="text/javascript" src="/lib/ueditor/1.4.3/ueditor.all.min.js"></script>
	<script type="text/javascript" src="/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
</body>
<script type="text/javascript">
  let listResult = new Vue({
    el: '#listResult',
    data: {
      depts: [],
      roles: []
    }
  });

  $(function () {
    $.ajax({
      url: '/accounts/selectRolesAndDepts',
      dataType: 'json',
      type: 'get',
      success: function (map) {
        listResult.roles = map.roles;
        listResult.depts = map.depts;
      }
    });
  });

  let closeWin = function () {
    let index = parent.layer.getFrameIndex(window.name);
    parent.show();
    parent.layer.close(index);
  };

  $('#cancelBtn').on('click', function () {
    closeWin();
  });

  $('#form-article-add').validate({
    onkeyup: false, //是否在敲击键盘时验证
    rules: {
      username: {
        required: true,
        remote: {
          url: '/accounts/isUsername',
          dataType: 'json',
          type: 'post',
          data: {
            username: function () {
              return $('#username').val();
            }
          }
        }
      },
      userpwd: {
        required: true
      },
      password_again: {
        required: true,
        equalTo: $('#userpwd')
      },
      realname: {
        required: true
      },
      mobile: {
        required: true
      },
      personid: {
        required: true
      },
      deptcode: {
        isIntGtZero: true
      },
      rolecode: {
        isIntGtZero: true
      }
    },
    messages: {
      username: {
        remote: '用户名重复'
      },
      password_again: {
        equalTo: '两次输入的密码必须一致'
      },
      realname: {},
      mobile: {},
      personid: {},
      deptcode: {
        isIntGtZero: '请选择所属部门'
      },
      rolecode: {
        isIntGtZero: '请选择角色'
      }
    },
    submitHandler: function () {
      console.log(111);
      $.ajax({
        url: '/accounts/add',
        data: $('#form-article-add').serialize(),
        dataType: 'json',
        type: 'post',
        success: function (flag) {
          if (flag) {
            closeWin();
          } else {
            layer.alert('添加失败，请稍后再试');
          }
        }
      });
    }
  });
</script>
</html>